'##################################################
'###  Top Level (Get root Path from system env)
'##################################################
function GetEnv(envVarName)
	On Error Resume Next
	' 创建Shell对象并获取值
	Set WshShell = CreateObject("WScript.Shell")
	envValue = WshShell.Environment("PROCESS")(envVarName) ' 优先查找进程级变量

	' 如果未找到则尝试系统级变量
	If Err.Number <> 0 Or envValue = "" Then
		Err.Clear
		envValue = WshShell.Environment("SYSTEM")(envVarName)
	End If

	' 如果仍未找到则尝试用户级变量
	If Err.Number <> 0 Or envValue = "" Then
		Err.Clear
		envValue = WshShell.Environment("USER")(envVarName)
	End If

	' 检查结果并输出
	If Err.Number = 0 And envValue <> "" Then
		GetEnv=envValue
	Else
		GetEnv=""
	End If
end function


' 设置注册表值函数
' 参数:
'   rootKey - 注册表根键 (如 "HKCU", "HKLM")
'   keyPath - 键路径 (如 "Software\MyApp")
'   valueName - 值名称
'   valueData - 要设置的值
'   valueType - 值类型 (默认为字符串, 可选: "REG_SZ", "REG_DWORD", "REG_BINARY")
Function SetRegistryValue(rootKey, keyPath, valueName, valueData, valueType)
    On Error Resume Next
    Dim shell, fullPath, regValue
    
    Set shell = CreateObject("WScript.Shell")
    
    ' 验证并转换根键
    Select Case UCase(rootKey)
        Case "HKCU": fullPath = "HKEY_CURRENT_USER\" & keyPath
        Case "HKLM": fullPath = "HKEY_LOCAL_MACHINE\" & keyPath
        Case "HKCR": fullPath = "HKEY_CLASSES_ROOT\" & keyPath
        Case "HKU":  fullPath = "HKEY_USERS\" & keyPath
        Case Else
            'SetRegistryValue = "错误: 无效的根键"
            Exit Function
    End Select
    
    ' 设置默认值类型
    If IsEmpty(valueType) Or valueType = "" Then valueType = "REG_SZ"
    
    ' 创建键路径 (如果不存在)
    shell.RegWrite fullPath & "\", "", "REG_SZ"
    
    ' 写入值
    shell.RegWrite fullPath & "\" & valueName, valueData, valueType
    
    If Err.Number <> 0 Then
        'SetRegistryValue = "错误: " & Err.Description
        Err.Clear
    Else
        'SetRegistryValue = "写入成功"
    End If
End Function

'##################################################
'##################################################
'##################################################
main
sub main()	
	envVarName ="EXP_SHORTCUTS_ROOT"
	dim root:root = GetEnv(envVarName)'"C:\MentorGraphics\2005EXP\SDD_HOME\pvtk\skill\A\"
	if root ="" then 
		msgbox "please set env value (EXP_SHORTCUTS_ROOT = ?)"
		exit sub
	end if
	
	dim tools
	tools = root & "\tools\EXP_Command.exe"
	dim fso
	set fso = createobject("scripting.filesystemobject")
	if fso.fileExists(tools) then
		createobject("wscript.shell").run tools
	end if
	set fso = nothing
	
	call SetRegistryValue("HKCU", "Software\MyApp", "EXP_Command", "", "REG_SZ")
	'###########
	Dim keyBindTables
	Set keyBindTables = Gui.Bindings("Document")
	keyBindTables.AddKeyBinding "Shift+F9","pr -dist *",1,1
	keyBindTables.AddKeyBinding "Ctrl+H","Edit->Highlight",0,1
	keyBindTables.AddKeyBinding "Ctrl+U","Edit->UnhighlightAll",0,1
	keyBindTables.AddKeyBinding "Ctrl+Q","Edit->Properties",0,1


	keyBindTables.AddKeyBinding "A","run " & root & "\skill\A\01_A.vbs",1,1
	keyBindTables.AddKeyBinding "B","run " & root & "\skill\A\02_B.vbs",1,1
	keyBindTables.AddKeyBinding "C","run " & root & "\skill\A\03_C.vbs",1,1
	keyBindTables.AddKeyBinding "D","run " & root & "\skill\A\04_D.vbs",1,1
	keyBindTables.AddKeyBinding "E","run " & root & "\skill\A\05_E.vbs",1,1
	keyBindTables.AddKeyBinding "F","run " & root & "\skill\A\06_F.vbs",1,1
	keyBindTables.AddKeyBinding "G","run " & root & "\skill\A\07_G.vbs",1,1
	keyBindTables.AddKeyBinding "H","run " & root & "\skill\A\08_H.vbs",1,1
	keyBindTables.AddKeyBinding "I","run " & root & "\skill\A\09_I.vbs",1,1
	keyBindTables.AddKeyBinding "J","run " & root & "\skill\A\10_J.vbs",1,1
	keyBindTables.AddKeyBinding "K","run " & root & "\skill\A\11_K.vbs",1,1
	keyBindTables.AddKeyBinding "L","run " & root & "\skill\A\12_L.vbs",1,1
	keyBindTables.AddKeyBinding "M","run " & root & "\skill\A\13_M.vbs",1,1
	keyBindTables.AddKeyBinding "N","run " & root & "\skill\A\14_N.vbs",1,1
	keyBindTables.AddKeyBinding "O","run " & root & "\skill\A\15_O.vbs",1,1
	keyBindTables.AddKeyBinding "P","run " & root & "\skill\A\16_P.vbs",1,1
	keyBindTables.AddKeyBinding "Q","run " & root & "\skill\A\17_Q.vbs",1,1
	keyBindTables.AddKeyBinding "R","run " & root & "\skill\A\18_R.vbs",1,1
	keyBindTables.AddKeyBinding "S","run " & root & "\skill\A\19_S.vbs",1,1
	keyBindTables.AddKeyBinding "T","run " & root & "\skill\A\20_T.vbs",1,1
	keyBindTables.AddKeyBinding "U","run " & root & "\skill\A\21_U.vbs",1,1
	keyBindTables.AddKeyBinding "V","run " & root & "\skill\A\22_V.vbs",1,1
	keyBindTables.AddKeyBinding "W","run " & root & "\skill\A\23_W.vbs",1,1
	keyBindTables.AddKeyBinding "X","run " & root & "\skill\A\24_X.vbs",1,1
	keyBindTables.AddKeyBinding "Y","run " & root & "\skill\A\25_Y.vbs",1,1
	keyBindTables.AddKeyBinding "Z","run " & root & "\skill\A\26_Z.vbs",1,1
	keyBindTables.AddKeyBinding "0","run " & root & "\skill\A\27_0.vbs",1,1
	keyBindTables.AddKeyBinding "1","run " & root & "\skill\A\28_1.vbs",1,1
	keyBindTables.AddKeyBinding "2","run " & root & "\skill\A\29_2.vbs",1,1
	keyBindTables.AddKeyBinding "3","run " & root & "\skill\A\30_3.vbs",1,1
	keyBindTables.AddKeyBinding "4","run " & root & "\skill\A\31_4.vbs",1,1
	keyBindTables.AddKeyBinding "5","run " & root & "\skill\A\32_5.vbs",1,1
	keyBindTables.AddKeyBinding "6","run " & root & "\skill\A\33_6.vbs",1,1
	keyBindTables.AddKeyBinding "7","run " & root & "\skill\A\34_7.vbs",1,1
	keyBindTables.AddKeyBinding "8","run " & root & "\skill\A\35_8.vbs",1,1
	keyBindTables.AddKeyBinding "9","run " & root & "\skill\A\36_9.vbs",1,1	
	keyBindTables.AddKeyBinding "Ctrl+F1","run " & root & "\skill\A\37_clearcommand.vbs",1,1
	keyBindTables.AddKeyBinding "Ctrl+Shift+S","run " & root & "\skill\A\38_Saveas.vbs",1,1
	keyBindTables.AddKeyBinding "_","run " & root & "\skill\A\39_Minus.vbs",1,1
	keyBindTables.AddKeyBinding "+","run " & root & "\skill\A\40_Plus.vbs",1,1
	keyBindTables.AddKeyBinding "Ctrl+D","run " & root & "\skill\A\41_swapparts.vbs",1,1
end sub





